﻿using Anley.DomainDrivenDesign.Contract.DependencyInjection;

namespace Anley.DomainDrivenDesign.Contract.Helper;

/// <summary>
/// 网络请求帮助接口
/// </summary>
public interface IHttpHelper
    : IScopedAutoInject
{
    /// <summary>
    /// GET/JSON请求
    /// </summary>
    /// <typeparam name="TRes"></typeparam>
    /// <param name="url"></param>
    /// <param name="queryParams"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    /// <remarks>请确认已通过<see cref="HostExtension.RegisterHttpClient(IServiceCollection)"/>或<see cref="HostExtension.RegisterHttpClient(IServiceCollection, string, string, int, int, int)"/>注入</remarks>
    Task<TRes?> GetJsonAsync<TRes>(
        string url,
        Dictionary<string, string>? queryParams = null,
        string? name = null)
        where TRes : class;

    /// <summary>
    /// POST/JSON请求
    /// </summary>
    /// <typeparam name="TRes"></typeparam>
    /// <param name="url"></param>
    /// <param name="requestParam"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    /// <remarks>请确认已通过<see cref="HostExtension.RegisterHttpClient(IServiceCollection)"/>或<see cref="HostExtension.RegisterHttpClient(IServiceCollection, string, string, int, int, int)"/>注入</remarks>
    Task<TRes?> PostJsonAsync<TRes>(
        string url,
        object? requestParam = null,
        string? name = null)
        where TRes : class;

    /// <summary>
    /// POST/JSON请求
    /// </summary>
    /// <typeparam name="TRes"></typeparam>
    /// <typeparam name="TReq"></typeparam>
    /// <param name="url"></param>
    /// <param name="requestParam"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    /// <remarks>请确认已通过<see cref="HostExtension.RegisterHttpClient(IServiceCollection)"/>或<see cref="HostExtension.RegisterHttpClient(IServiceCollection, string, string, int, int, int)"/>注入</remarks>
    Task<TRes?> PostJsonAsync<TRes, TReq>(
        string url,
        TReq requestParam,
        string? name = null)
        where TRes : class;

    /// <summary>
    /// POST/FORM请求
    /// </summary>
    /// <param name="url"></param>
    /// <param name="formData"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    /// <remarks>请确认已通过<see cref="HostExtension.RegisterHttpClient(IServiceCollection)"/>或<see cref="HostExtension.RegisterHttpClient(IServiceCollection, string, string, int, int, int)"/>注入</remarks>
    Task<string?> PostFormAsync(
        string url,
        Dictionary<string, string>? formData = null,
        string? name = null);

    /// <summary>
    /// POST/FORM请求
    /// </summary>
    /// <param name="url"></param>
    /// <param name="formData"></param>
    /// <param name="fileData"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    /// <remarks>请确认已通过<see cref="HostExtension.RegisterHttpClient(IServiceCollection)"/>或<see cref="HostExtension.RegisterHttpClient(IServiceCollection, string, string, int, int, int)"/>注入</remarks>
    Task<string?> PostFormAsync(
        string url,
        Dictionary<string, string>? formData = null,
        Dictionary<string, IFormFile>? fileData = null,
        string? name = null);
}